package cn.gok.util;

import java.util.Map;
import java.util.TreeMap;

class Animal{
    private String name;
    private int feetCount;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getFeetCount() {
        return feetCount;
    }

    public void setFeetCount(int feetCount) {
        this.feetCount = feetCount;
    }

    public Animal(String name, int feetCount) {
        this.name = name;
        this.feetCount = feetCount;
    }

    @Override
    public String toString() {
        return "Animal{" +
                "name='" + name + '\'' +
                ", feetCount=" + feetCount +
                '}';
    }

}
public class TreeMap例子 {
    public static void main(String[] args) {
        //默认排序();
        自定义排序();
    }

    private static void 自定义排序() {
        Map<Animal,String> map=new TreeMap<>();
        map.put(new Animal("老虎",4),"houhouhou");
        map.put(new Animal("小鸡",2),"jijiji");
        map.put(new Animal("蛇",0),"sisisi");
    }

    private static void 默认排序() {
        Map<Integer,String> map=new TreeMap<>();
        map.put(10,"aaa");
        map.put(5,"bbb");
        map.put(8,"ccc");
        System.out.println(map);//数值从小到大

        Map<String,String> map2=new TreeMap<>();
        map2.put("a","aaa");
        map2.put("ab","bbb");
        map2.put("bz","ccc");
        System.out.println(map2);
    }
}
